using System;
using System.Collections.Generic;
using System.Text;

namespace Elev.Core.Calculator
{
    public class AverageCalculator : IAverageCalculator
    {
        #region IAverageCalculator Members

        public object Calculate(object[] Items)
        {
            double sum = 0;
            int nbGrades = 0;
            foreach (ICalculable i in Items)
            {
                if (i.Mark > -1)
                {
                    sum += i.Mark * i.Coefficient;
                    nbGrades += i.Coefficient;
                }
            }

            if (nbGrades > 0)
                return Math.Round((double)(sum / (double)nbGrades), 2);

            return (double)-1;
        }

        #endregion
    }
}
